home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-06-19 | 3.9 KB | 186 lines | [TEXT/PJMM] |
- program pwbk;
-
-
- { This is the source to Brian Gaeke's Powerbook Compatibility INIT. }
- { As you can see, it's not an INIT, but an appe.... but who cares? }
- { This was finished DURING the hack contest. :) }
-
- {$I-}
-
-
- uses
- Notification, Traps, Shutdown;
- const
- reserve_power = -16511;
- very_little = -16512;
- good_night = -16513;
- battery_sicn = -16386;
- var
- starttime, nowtime, threshold: longint;
- theID, iterations: Integer;
- gNotify: NMRec;
- gGoOn, notifySent: boolean;
- event: eventrecord;
- tempString: StringHandle;
- theStr: Str255;
- i: array[1..3] of str255;
- gotevent: boolean;
-
- procedure NM_COMPLETION (theNMRec: NMRecPtr);
- var
- a5: longint;
- err: integer;
- begin
- a5 := SetA5(theNMRec^.nmRefCon);
- gGoOn := true;
- err := NMRemove(theNMRec);
- a5 := SetA5(a5);
- end;
-
- procedure DoNotify (str_res_id: integer);
- var
- err: OsErr;
- begin
- gNotify.qtype := 8;
- gNotify.nmmark := 0;
- gNotify.nmsound := Handle(-1);
- gNotify.nmresp := @NM_COMPLETION;
- gNotify.nmicon := GetResource('SICN', battery_sicn);
- gNotify.nmrefcon := SetCurrentA5;
- gGoOn := false;
- tempString := StringHandle(GetResource('STR ', str_res_id));
- if tempString = nil then
- begin
- SysBeep(5);
- ExitToShell;
- end;
- BlockMove(Ptr(tempString^), @theStr, Integer(tempString^^[0]) + 1);
- ReleaseResource(Handle(tempString));
- gNotify.nmstr := @theStr;
- err := NMInstall(@gNotify);
- if err <> noerr then
- begin
- SysBeep(1);
- SysBeep(1);
- ExitToShell;
- end;
- end;
-
- function OnPortable: boolean;
- var
- err: OSErr;
- result: longint;
- {Note: The following local routines are from the Compatibility Guidelines section}
- {of IM VI. They are gtt=GetTrapType, ntt=NumToolboxTraps, ok=TrapAvailable,}
- {and gestaltok=GestaltAvailable. I had to use $A1AD in gestaltok because the @&^$#(@#}
- {THINK Pascal interfaces don't have _Gestalt!? (or something....)}
- function gtt (tr: integer): traptype;
- begin
- if BAND(tr, $800) > 0 then
- gtt := tooltrap
- else
- gtt := ostrap;
- end;
- function ntt: integer;
- begin
- if NGetTrapAddress(_InitGraf, tooltrap) = NGetTrapAddress($AA6E, tooltrap) then
- ntt := $200
- else
- ntt := $400;
- end;
- function ok (tr: integer): boolean;
- var
- tt: traptype;
- begin
- tt := gtt(tr);
- if tt = tooltrap then
- begin
- tr := BAND(tr, $07ff);
- if tr >= ntt then
- tr := _Unimplemented;
- end;
- ok := ngettrapaddress(tr, tt) <> ngettrapaddress(_unimplemented, tooltrap);
- end;
- function gestaltok: boolean;
- begin
- gestaltok := ok($A1AD);
- end;
- begin
- OnPortable := false;
- if not gestaltok then
- ExitToShell;
- err := gestalt(gestaltPowerMgrAttr, result);
- if err <> noErr then
- ExitToShell;
- if result > 0 then
- onPortable := true;
- end;
-
- function setNext (its: integer): longint;
- var
- t: str255;
- tmp: longint;
- begin
- nowtime := tickcount;
- case its of
- 1:
- tmp := nowtime + 7200;
- 2:
- tmp := nowtime + 3600;
- 3:
- tmp := nowtime + 600;
- 4:
- ShutDwnPower;
- end;
- setNext := tmp;
- end;
-
- function setIDnext (it: integer): integer;
- begin
- case it of
- 1:
- setIDnext := reserve_power;
- 2:
- setIDnext := very_little;
- 3:
- setIDnext := good_night;
- end;
- end;
-
- begin
- InitGraf(@ThePort);
-
- if OnPortable then
- if not button then
- ;
- {ExitToShell}
- {Originally, I had planned to run only on machines without a Power Mgr.}
- {I think we should just continue in the quest to confuse, and run anyway.}
-
- startTime := tickcount;
- threshold := setNext(1);
- theID := setIDnext(1);
- iterations := 1;
-
- repeat
- gotEvent := WaitNextEvent(0, event, 400, nil);
-
- nowtime := tickcount;
- if nowtime >= threshold then
- begin
- if not notifySent then
- begin
- doNotify(theID);
- notifySent := true;
- end;
- end;
- if gGoOn then
- begin
- gGoOn := false;
- iterations := iterations + 1;
- threshold := setNext(iterations);
- theID := setIDnext(iterations);
- notifySent := false;
- end;
- until false;
- end.